/***** * * Grant's CGI Shell (Common Grant Interface :-) * http://arpp1.carleton.ca/grant/mac/grantscgi.html * * MyCGIProcess.c * * Sample application using the cgi interface. * * MyCGIProcess is where you will do your application specific processing * of the cgi stuff. * * by Grant Neufeld * * Copyright ©1995 by Grant Neufeld * * http://arpp1.carleton.ca/grant/ * gneufeld@ccs.carleton.ca * grant@acm.org * * This source may be freely used as long as the copyright notice is kept in the source. * I ask that you let me know of any enhancements (read: bug fixes) to this code. * I would also like copies of (or discounts on) anything you produce using this code, please. * *****/ #include "MyConfiguration.h" #if kCompileWithCGICode #include #include #include "compiler_stuff.h" #include "globals.h" #include "CGI.h" #include "MemoryUtil.h" /*** CUSTOM CGI FUNCTION ***/ /* This function is where the CGI is actually processed. You should replace its contents with your own. You need to allocate (*theCGIHandle)->responseData using MyNewPtr. Put an HTTP header at the beginning of (*theCGIHandle)->responseData. Put your data immediately following the last character of the HTTP header. (*theCGIHandle)->responseData will be automatically deallocated by the CGI handler. You should set (*theCGIHandle)->responseSize to be the size of the responseData, including null terminator if you have one. (this function's prototype is defined in CGI.h) */ void MyCGIProcess ( CGIHdl theCGIHandle ) { (*theCGIHandle)->responseSize = gHTTPHeaderOKSize + 141 /* size of my constant string */ + 1 /* null terminator */; (*theCGIHandle)->responseData = (char *) MyNewPtr ( (*theCGIHandle)->responseSize, nil ); if ( (*theCGIHandle)->responseData != nil ) { HLock ( (Handle)theCGIHandle ); strcpy ( (*theCGIHandle)->responseData, (char *)gHTTPHeaderOK ); strcpy ( &(((*theCGIHandle)->responseData)[gHTTPHeaderOKSize]), "\rGrant's CGI Framework<TITLE>\r<BODY>This framework doesn't do anything. You must add your own code to generate useful results.</BODY>\r" ); HUnlock ( (Handle)theCGIHandle ); } else { (*theCGIHandle)->responseSize = nil; } /* you should try to make liberal use of yielding to other threads, especially in for and while loops */ #if kCompileWithThreadsOptional if ( gHasThreadMgr ) #endif { YieldToAnyThread (); } /* set application to quit after finishing the event */ // gQuit = true; } /* MyCGIProcess */ /*** CUSTOM CGI INITIALIZATION ***/ #pragma segment Startup /* Put any of the initialization you need done, here. This function will be called once: in-between the startup sequence and the main event loop. Return true if the initialization was successful, otherwise false. An initialization failure will result in the application quitting. */ Boolean MyCGIStartup ( void ) { return true; } /* MyCGIStartup */ /*** CUSTOM CGI CLEAN UP ***/ #pragma segment Main /* This function is called at quitting time. Put any cleanup you need to do in it. */ Boolean MyCGIQuit ( Boolean allowUserInteract ) { return true; }/* MyCGIQuit */ #endif /* kCompileWithCGICode */ /*** EOF ***/